package controllers

import javax.inject.Inject
import dao._
import play.api.data.Forms._
import play.api.data._
import play.api.libs.json.Json
import play.api.mvc._
import play.api.data.format.Formats._

import scala.concurrent.ExecutionContext.Implicits.global
import models.Tables._
import implicits.Implicits._
import tool.FormTool
import utils.Utils

/**
 * Created by yz on 2017/6/20.
 */
class BrowseController @Inject()(browseCircRnaDao: BrowseCircRnaDao,
                                 browseLongRnaDao: BrowseLongRnaDao, cc: ControllerComponents) extends
  AbstractController(cc) {

  def toIndex = Action {implicit request=>
    val data=FormTool.kindOpForm.bindFromRequest().get
    Ok(views.html.browse.index(data.kind))
  }

  def toSamplesIndex = Action {
    Ok(views.html.browse.samplesIndex())
  }

//  def getSamples = Action.async {
//    circAllPositionsDao.selectSamples.map { x =>
//      val array = x.map(y => Json.obj("id" -> y, "text" -> y))
//      Ok(Json.toJson(array))
//    }
//  }

//  def getLongSamples = Action.async {
//    longrnageneannotationDao.selectSamples.map { x =>
//      val array = x.map(y => Json.obj("id" -> y, "text" -> y))
//      Ok(Json.toJson(array))
//    }
//  }

  def getCircRnaSampleTypes = Action.async {
    browseCircRnaDao.selectAllSampleTypes.map { x =>
      val types = x.flatMap { x =>
        x.mySplit(";")
      }.map(_.trim).distinct
      Ok(Json.toJson(types))
    }
  }

  def getDiffSamples = Action.async {
    browseCircRnaDao.selectDiffSamples.map { x =>
      val array = x.map(y => Json.obj("id" -> y, "text" -> y))
      Ok(Json.toJson(array))
    }
  }

  def getAllGeneSymbols: Action[AnyContent] = Action.async { implicit request =>
    browseCircRnaDao.selectAllGeneSymbol.map { x =>
      Ok(Json.toJson(x))
    }
  }

}